package net.maku.association.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.association.convert.InterestAssociationCommunityConvert;
import net.maku.association.entity.InterestAssociationCommunityEntity;
import net.maku.association.query.InterestAssociationCommunityQuery;
import net.maku.association.vo.InterestAssociationCommunityVO;
import net.maku.association.dao.InterestAssociationCommunityDao;
import net.maku.association.service.InterestAssociationCommunityService;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 协会社区
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2025-04-26
 */
@Service
@AllArgsConstructor
public class InterestAssociationCommunityServiceImpl extends BaseServiceImpl<InterestAssociationCommunityDao, InterestAssociationCommunityEntity> implements InterestAssociationCommunityService {

    @Override
    public PageResult<InterestAssociationCommunityVO> page(InterestAssociationCommunityQuery query) {
        IPage<InterestAssociationCommunityEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(InterestAssociationCommunityConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<InterestAssociationCommunityEntity> getWrapper(InterestAssociationCommunityQuery query){
        LambdaQueryWrapper<InterestAssociationCommunityEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(InterestAssociationCommunityVO vo) {
        InterestAssociationCommunityEntity entity = InterestAssociationCommunityConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(InterestAssociationCommunityVO vo) {
        InterestAssociationCommunityEntity entity = InterestAssociationCommunityConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}